﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace AppPriceLive
{
    public partial class SmtpMailMessage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnSend_Click(object sender, EventArgs e)
        {
            string EmailName = ConfigurationManager.AppSettings["EmailName"];
            string Password = ConfigurationManager.AppSettings["Password"];

            // Smtp configuration
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.Credentials = new NetworkCredential(EmailName, Password);
            smtpClient.Port = int.Parse(ConfigurationManager.AppSettings["PortNo"]);
            smtpClient.Host = ConfigurationManager.AppSettings["HostName"];
            smtpClient.EnableSsl = bool.Parse(ConfigurationManager.AppSettings["EnableSsl"]);

            MailMessage mailMessage = new MailMessage();
            String[] addr = txtTo.Text.Split(',');
            try
            {
                mailMessage.From = new MailAddress(EmailName);
                Byte i;
                for (i = 0; i < addr.Length; i++)
                    mailMessage.To.Add(addr[i]);
                mailMessage.Subject = txtSubject.Text;
                mailMessage.Body = txtConTent.Text;

                mailMessage.IsBodyHtml = true;
                mailMessage.BodyEncoding = Encoding.UTF8;
                mailMessage.Priority = MailPriority.Normal;
                mailMessage.ReplyTo = new MailAddress(txtTo.Text);

                smtpClient.Send(mailMessage);
            }
            catch (Exception ex) { }

        }
    }
}
